<?php
class guestbook extends spController
{
	function __construct(){ 
		parent::__construct(); 
		require("lib/myextendClass/mailer.class.php");
		$this->gdlink=spClass('link_list')->findAll();
		$this->banner=spClass('page_img')->findAll('nid=1');
		
		$sitesystem=spClass("site_system")->find("id=1"); 
		
		$comma_separated=explode(',',$sitesystem["skeyword"]);
		
		$this->config222=$comma_separated;
		
		$this->sitesystem=$sitesystem;
		
		$this->banner5=spClass('page_img')->findAll('nid=5');
		
		
		$this->promotegoods=spClass('goods_list')->findAll('id>0 and promote=1','sort_id asc,id desc limit 2');
		
		$this->catlist=spClass('goods_cat')->findAll('pid=0','sort_id asc,id desc');
		
		$this->ryzslist=spClass('article_list')->findall('pid=54','sort_id asc,id desc limit 2');
		
		$this->zxsplist=spClass('article_list')->findall('pid=55','sort_id asc,id desc limit 1');
		
				$this->pabtrows = spClass("article_list")->findAll("pid=49","sort_id asc,id asc");
		
		$this->newrows = spClass("article_cat")->findAll("pid=4","sort_id asc,id desc");
		
		//$this->catlist=spClass('goods_cat')->findAll('pid=0','sort_id asc,id desc');
		
		$this->cabtrows = spClass("article_list")->findAll("pid=53","sort_id asc,id asc");
		
				$cat_select12  = spClass("goods_cat")->findAll("pid=0","sort_id asc");
		foreach($cat_select12 as $c_ss=>$c_valuee){
		$cat_select12[$c_ss]['second']  = spClass("goods_cat")->findAll("pid=".$c_valuee['id'],"sort_id asc");
		 }
		$this->cat_select12=$cat_select12; 
	}
	
	function index(){ 
		$this->title    = spClass("site_config")->find("id=101");  
		$this->keywords = spClass("site_config")->find("id=104");  
		$this->desc     = spClass("site_config")->find("id=103");
		
		$this->sitesystem=spClass("site_system")->find("id=1");
		
		
		$this->abtrows= spClass("article_list")->findAll("pid=53","sort_id asc,id asc");

		// $id=!empty($_GET['id'])?$_GET['id']:$this->error('参数错误',spUrl('news','treat'));
		
		// $row=spClass('member_product')->find('id='.$id);
		// $this->user=spClass('member_list')->find('id='.$row['sid']);
		
		// $this->row=$row;
		
		$this->menuIndex=5;
		
		$this->type     = "客户留言"; 
		$this->display("index/guestbook.html");
	}
	
	//发布留言
	function add(){ 
		$cmpname      = empty($_POST['cmpname'])?"":$_POST['cmpname'];
		$cname      = empty($_POST['cname'])?"":$_POST['cname'];
		$tels      = empty($_POST['tels'])?"":$_POST['tels'];
		$email    = empty($_POST['email'])?"":$_POST['email'];
		$content    = empty($_POST['content'])?"":$_POST['content'];
		$content=strip_tags($content);
		if(empty($tels)){
			$this->error("请填写电话号码",spUrl("main","index"));
			exit();
		}else{
			$newrow = array(
				'cmpname'      => $cmpname,
				'cname'      => $cname,
				'tels'    => $tels,
				'title'    => $email,
				'content'    => $content,
				'add_time'   => time(),
			);
			if($row=spClass('feedback')->create($newrow)){	
				if(empty($frompage)){
					$this->error("您的留言信息已经提交",spUrl("main","index"));
				}else{
					$this->error("您的留言信息已经提交",spUrl("main","index"));
				}
			}
		}	
	}
	
	
	
	
	function dingyue(){ 
		$this->title    = spClass("site_config")->find("id=101");  
		$this->keywords = spClass("site_config")->find("id=104");  
		$this->desc     = spClass("site_config")->find("id=103");
		
		$id      = empty($_GET['id'])?$this->error('参数错误！'):$_GET['id'];
		
		$product=spClass('goods_list')->find('id='.$id);
		
		$this->productname=$product['title'];
		
		$this->catlist=spClass('goods_cat')->findAll('id>0','sort_id asc,id desc');
				
		
		//$this->gblist   = spClass("feedback")->findAll("promote=1");
		
		$this->row=spClass('article_list')->find('id=229');

		$this->banner=spClass('page_img')->find('id=32');
		$this->menuIndex=3;
		$this->type     = "客户留言"; 
		$this->display("index/dingyue.html");
	}
	
	//发布留言
	function dingyueadd(){ 
		$username = empty($_POST['username'])?"":$_POST['username'];
		$email    = empty($_POST['email'])?"":$_POST['email'];
		$phone    = empty($_POST['phone'])?"":$_POST['phone'];
		$address  = empty($_POST['address'])?"":$_POST['address'];
		$product  = empty($_POST['product'])?"":$_POST['product'];
		$content  = empty($_POST['content'])?"":$_POST['content'];
		$company  = empty($_POST['company'])?"":$_POST['company'];
		$num      = empty($_POST['num'])?1:$_POST['num'];
		$id      = empty($_POST['id'])?$this->error('参数错误！'):$_POST['id'];
		
		// print_r($_POST);
		// exit();
		
		
		if(empty($username) or empty($email) or empty($phone) or empty($address) or empty($product) or empty($content) or empty($num)){
			$this->error("请填写完整",spUrl("guestbook","dingyue",array('id'=>$id)));
		}else{
			$newrow = array(
				'username'   => $username,
				'email'      => $email,
				'phone'      => $phone,
				'address'    => $address,
				'product'    => $product,
				'sid'    => $id,
				'content'    => $content,
				'num'        => $num,
				'add_time'   => time(),
			);
			if($row=spClass('dingyue')->create($newrow)){	
				if(empty($frompage)){
					$this->error("感谢您的留言!",spUrl("guestbook","dingyue",array('id'=>$id)));
				}else{
					$this->error("感谢您的留言!",spUrl("guestbook","dingyue",array('id'=>$id)));
				}
			}
		}	
	}
	
	//cupon
	
	function cupon(){ 
		$this->title    = spClass("site_config")->find("id=101");  
		$this->keywords = spClass("site_config")->find("id=104");  
		$this->desc     = spClass("site_config")->find("id=103");

		//$this->gblist   = spClass("feedback")->findAll("promote=1");
		
		$this->row=spClass('article_list')->find('id=230');

		$this->banner=spClass('page_img')->find('id=32');
		$this->menuIndex=1;
		$this->type     = "客户留言"; 
		$this->display("index/cupon.html");
	}
	
	//发布留言
	function cuponadd(){ 
		$username = empty($_POST['username'])?"":$_POST['username'];
		$email    = empty($_POST['email'])?"":$_POST['email'];
		$province = empty($_POST['province'])?"":$_POST['province'];
		$city     = empty($_POST['city'])?"":$_POST['city'];
		$postcode = empty($_POST['postcode'])?0:$_POST['postcode'];
		$phone    = empty($_POST['phone'])?"":$_POST['phone'];
		$address  = empty($_POST['address'])?"":$_POST['address'];
		$dog_type = empty($_POST['dog_type'])?"":$_POST['dog_type'];
		$dog_name = empty($_POST['dog_name'])?"":$_POST['dog_name'];
		
		if(empty($username) or empty($email) or empty($phone) or empty($province) or empty($city) or empty($postcode) or empty($dog_type) or empty($dog_name) or empty($address)){
			$this->error("请填写完整",spUrl("guestbook","cupon"));
		}else{
			$newrow = array(
				'username'   => $username,
				'email'      => $email,
				'province'   => $province,
				'city'       => $city,
				'postcode'   => $postcode,
				'address'    => $address,
				'phone'      => $phone,
				'dog_type'   => $dog_type,
				'dog_name'   => $dog_name,
				'add_time'   => time(),
			);
			if($row=spClass('feedback')->create($newrow)){	
				if(empty($frompage)){
					$this->error("感谢您的留言!",spUrl("guestbook","cupon"));
				}else{
					$this->error("感谢您的留言!",spUrl("guestbook","cupon"));
				}
			}
		}	
	}
	
	
}	